package cn.stylefeng.guns.modular.lx.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.lx.entity.LxProductJyk;
import cn.stylefeng.guns.modular.lx.mapper.LxProductJykMapper;
import cn.stylefeng.guns.modular.lx.model.params.LxProductJykParam;
import cn.stylefeng.guns.modular.lx.model.result.LxProductJykResult;
import  cn.stylefeng.guns.modular.lx.service.LxProductJykService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jyk
 * @since 2023-12-14
 */
@Service
public class LxProductJykServiceImpl extends ServiceImpl<LxProductJykMapper, LxProductJyk> implements LxProductJykService {

    @Override
    public void add(LxProductJykParam param){
        LxProductJyk entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(LxProductJykParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(LxProductJykParam param){
        LxProductJyk oldEntity = getOldEntity(param);
        LxProductJyk newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public LxProductJykResult findBySpec(LxProductJykParam param){
        return null;
    }

    @Override
    public List<LxProductJykResult> findListBySpec(LxProductJykParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(LxProductJykParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(LxProductJykParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private LxProductJyk getOldEntity(LxProductJykParam param) {
        return this.getById(getKey(param));
    }

    private LxProductJyk getEntity(LxProductJykParam param) {
        LxProductJyk entity = new LxProductJyk();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }
    public void reduceChl(int id) {
        this.baseMapper.reduceChl(id);
    }
}


